package com.jsf.controller;


import com.baomidou.mybatisplus.extension.service.IService;
import com.jsf.entity.Equipment;
import com.jsf.entity.Member;
import com.jsf.entity.Tj;
import com.jsf.service.IEquipmentService;
import com.jsf.service.IMemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author jsf
 * @since 2022-02-21
 */
@RestController
@RequestMapping("/member")
public class MemberController {
    @Autowired
    private IMemberService ms;
    @GetMapping("/selectAll")
    public List<Member> selectAll(){
        return ms.list();
    }

    @PostMapping("/add")
    public void add(@RequestBody Member member){
        ms.save(member);
    }
    @DeleteMapping("/delete/{id}")
    public void delete(@PathVariable("id") int id){
        ms.removeById(id);
    }
    @GetMapping("/selectOne/{id}")
    public Member selectOne(@PathVariable("id") int id){
        return ms.getById(id);
    }
    @PutMapping("/update")
    public void update(@RequestBody Member member){
        ms.updateById(member);
    }
    @GetMapping("/selectMemberTj")
    public List<Tj> selectMemberTj(){
        List<Member> list = ms.list();
        int men=0;
        int women=0;
        if(list!=null){
            for(Member m:list){
                if(m.getGender()!=null&&m.getGender()==0){
                    women++;
                }
                if(m.getGender()!=null&&m.getGender()==1){
                    men++;
                }
            }
        }
         Tj tj1=new Tj();
        tj1.setSex("男");
        tj1.setCount(men);
        Tj tj2=new Tj();
        tj2.setSex("女");
        tj2.setCount(women);
        List<Tj> result=new ArrayList<>();
        result.add(tj1);
        result.add(tj2);
        return result;
    }
}

